//
//  StatusCellBottomView.swift
//  个人微博
//
//  Created by 一介布衣 on 16/2/22.
//  Copyright © 2016年 HUAMANLOU. All rights reserved.
//

import UIKit

class StatusCellBottomView: UIView {

    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor(white: 0.8, alpha: 1)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // 设置界面
    private func setupUI() {
        addSubview(repostBtn)
        addSubview(commentBtn)
        addSubview(oYeahBtn)
        
        let sepView1 = sepView()
        let sepView2 = sepView()
        addSubview(sepView1)
        addSubview(sepView2)
        
        // 设置约束
        repostBtn.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            make.left.equalTo(self.snp_left)
        }
        
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            make.left.equalTo(repostBtn.snp_right)
            make.width.equalTo(repostBtn.snp_width)
        }
        
        oYeahBtn.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            make.left.equalTo(commentBtn.snp_right)
            // 三等分的第一步，最右边的视图添加相对于父视图右边的约束
            make.right.equalTo(self.snp_right)
            make.width.equalTo(commentBtn.snp_width)
        }
        
        sepView1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(repostBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            // 黄金分割比 1:0.618
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(0.5)
        }
        
        sepView2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(0.5)
        }
        
        // 添加点击事件
        repostBtn.addTarget(self, action: "repostBtnDidClick", forControlEvents: .TouchUpInside)
    }
    
    //MARK: - 用户点击事件
    // 每一个继承自UIResponder的对象，都会添加到响应者链条中
    // 就需要遍历响应者链条，来获取导航视图控制器，进行页面的跳转
    @objc private func repostBtnDidClick() {
        let tempVc = TempViewController()
        navViewController()?.pushViewController(tempVc, animated: true)
        
    }
    
    private func sepView()->(UIView) {
        let view = UIView()
        view.backgroundColor = UIColor.darkGrayColor()
        return view
    }
    
    
    // 懒加载视图
    // 转发按钮
    private lazy var repostBtn:UIButton = UIButton(backImageName: nil, text: "转发", textColor: UIColor.lightGrayColor(), imageName: "timeline_icon_retweet")
    //评论按钮
    private lazy var commentBtn:UIButton = UIButton(backImageName: nil, text: "评论", textColor: UIColor.lightGrayColor(), imageName: "timeline_icon_comment")
    // 点赞按钮
    private lazy var oYeahBtn:UIButton = UIButton(backImageName: nil, text: "点赞", textColor: UIColor.lightGrayColor(), imageName: "timeline_icon_unlike")
}





